﻿Imports System.Data.SqlClient

Public Class Dvehiculo
    Inherits Conexion
    Dim cmd As New SqlCommand

    Public Function guardar(ByVal dts As Entidades.Evehiculo) As Boolean
        Try
            conectado()
            cmd = New SqlCommand("sp_guardarvehiculo")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn
            cmd.Parameters.AddWithValue("@dominio", dts.dominiovehiculo)
            cmd.Parameters.AddWithValue("@marca", dts.marcavehiculo)
            cmd.Parameters.AddWithValue("@tipo", dts.tipovehiculo)
            cmd.Parameters.AddWithValue("@modelo", dts.modelovehiculo)
            cmd.Parameters.AddWithValue("@marca_motor", dts.marcamotor)
            cmd.Parameters.AddWithValue("@num_motor", dts.nummotor)
            cmd.Parameters.AddWithValue("@marca_chasis", dts.marcachasis)
            cmd.Parameters.AddWithValue("@num_chasis", dts.numchasis)
            cmd.Parameters.AddWithValue("@uso", dts.usovehiculo)

            If cmd.ExecuteNonQuery Then
                Return True
            Else
                Return False
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        Finally
            desconectado()
        End Try
    End Function

    Public Function modificar(ByVal Vehiculo As Entidades.Evehiculo) As Boolean
        Try
            conectado()
            cmd = New SqlCommand("sp_modificarvehiculo")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn
            cmd.Parameters.AddWithValue("@dominio", Vehiculo.dominiovehiculo)
            cmd.Parameters.AddWithValue("@marca", Vehiculo.marcavehiculo)
            cmd.Parameters.AddWithValue("@tipo", Vehiculo.tipovehiculo)
            cmd.Parameters.AddWithValue("@modelo", Vehiculo.modelovehiculo)
            cmd.Parameters.AddWithValue("@marca_motor", Vehiculo.marcamotor)
            cmd.Parameters.AddWithValue("@num_motor", Vehiculo.nummotor)
            cmd.Parameters.AddWithValue("@marca_chasis", Vehiculo.marcachasis)
            cmd.Parameters.AddWithValue("@num_chasis", Vehiculo.numchasis)
            cmd.Parameters.AddWithValue("@uso", Vehiculo.usovehiculo)

            If cmd.ExecuteNonQuery Then
                Return True
            Else
                Return False
            End If


        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        Finally
            desconectado()

        End Try
    End Function


    Public Function eliminar(ByVal dts As Entidades.Evehiculo) As Boolean
        Try
            conectado()
            cmd = New SqlCommand("sp_eliminarvehiculo")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn
            cmd.Parameters.AddWithValue("@dominio", dts.dominiovehiculo)


            If cmd.ExecuteNonQuery Then
                Return True
            Else
                Return False
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        Finally
            desconectado()
        End Try
    End Function


    Public Function buscar(ByVal Vehiculo As String) As DataTable
        Try
            conectado()
            cmd = New SqlCommand("sp_buscarvehiculo")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn
            cmd.Parameters.AddWithValue("@dominio", Vehiculo)
            Dim DA As New SqlDataAdapter(cmd)
            Dim TABLA As New DataTable
            TABLA.Clear()
            DA.Fill(TABLA)
            Return TABLA

            Return Nothing


        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        Finally
            desconectado()
        End Try
    End Function

End Class
